var _api = _interopRequireDefault(require("../../../utils/api"));

function _interopRequireDefault(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

function _objectSpread(e) {
    for (var t = 1; t < arguments.length; t++) {
        var i = null != arguments[t] ? arguments[t] : {}, a = Object.keys(i);
        "function" == typeof Object.getOwnPropertySymbols && (a = a.concat(Object.getOwnPropertySymbols(i).filter(function(t) {
            return Object.getOwnPropertyDescriptor(i, t).enumerable;
        }))), a.forEach(function(t) {
            _defineProperty(e, t, i[t]);
        });
    }
    return e;
}

function _defineProperty(t, e, i) {
    return e in t ? Object.defineProperty(t, e, {
        value: i,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : t[e] = i, t;
}

var RESET_CAT = {
    catid: "my",
    name: "我的客户",
    checked: !0
}, ROOT_CAT = {
    catid: "0",
    name: "所有成员",
    checked: !0
}, types = {
    analyze: {
        handlelist: function(t) {
            var e = [], i = this.query.catid;
            e = this.isHigher ? e.concat(t || []) : [ _objectSpread({}, ROOT_CAT) ].concat(t[0].children || []), 
            this.setData({
                list: e,
                catid: String(i)
            });
        },
        action: function(t) {
            console.log(t), this.$emit("radar.department.change", t), this.$route("back");
        }
    },
    niche: {
        handlelist: function(t) {
            var e, i, a = this.query.catid;
            e = [ RESET_CAT, _objectSpread({}, ROOT_CAT) ], this.isHigher ? i = (e = e.concat(t)).filter(function(t) {
                return 0 < t.catid;
            }).map(function(t) {
                return t.catid;
            }).join(",") : ((e = e.concat(t[0].children || []))[1].catid = i = t[0].catid, a = 0 == +a ? i : a);
            var n = a.split(",");
            e = e.map(function(t) {
                return t.checked = n.includes(t.catid), t;
            }), this.allCatid = i, this.setData({
                list: e,
                catid: String(a)
            });
        },
        action: function(t) {
            0 == +t.catid && (t.isAllCat = !0, t.catid = this.allCatid), this.$emit("niche.department.change", t), 
            this.$route("back");
        }
    }
};

Page({
    data: {
        list: []
    },
    onLoad: function(t) {
        this.query = t, this.loadList();
    },
    onReady: function() {
        this.dialog = this.selectComponent("#dialog");
    },
    loadList: function() {
        var e = this, t = this.query, i = t.cardid, a = t.guid, n = t.ishigher, r = t.type, c = {
            guid: a
        };
        (this.isHigher = 1 == +n) && (c.cardid = i, c.ishigher = n), _api.default.minicard.category.lists({
            data: c
        }).then(function(t) {
            types[r].handlelist.call(e, t.data);
        });
    },
    onConfirm: function(t) {
        var e = t.detail.value;
        types[this.query.type].action.call(this, e);
    }
});